/*
 * @lc app=leetcode.cn id=824 lang=javascript
 *
 * [824] 山羊拉丁文
 */

// @lc code=start
/**
 * @param {string} sentence
 * @return {string}
 */
var toGoatLatin = function (sentence) {
  const au = ['a', 'e', 'i', 'o', 'u']
  return sentence
    .split(' ')
    .map((word, index) => {
      if (au.includes(word.toLocaleLowerCase().charAt(0))) {
        return word + 'ma' + new Array(index + 1).fill('a').join('');
      } else {
        return word.slice(1) + word.charAt(0) + 'ma' + new Array(index + 1).fill('a').join('');
      }
    })
    .join(' ');
};
// @lc code=end